package com.ljf.authority.api.service.impl;

import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.ljf.authority.domain.repository.AuthorityBaseMenuTabulationRepository;
import com.ljf.authority.domain.service.AuthorityBaseMenuTabulationDomainService;
import com.ljf.authority.domain.validator.AuthorityBaseMenuTabulationValidator;
import com.ljf.authority.dto.command.*;
import com.ljf.authority.dto.query.AuthorityBaseMenuTabulationQuery;
import com.ljf.authority.model.AuthorityBaseMenuTabulation;
import com.ljf.authority.service.IAuthorityBaseMenuTabulationService;
import com.ljf.authority.vo.*;
import com.ljf.common.api.service.impl.BasisServiceImpl;
import com.ljf.common.exception.ServiceException;
import com.ljf.common.result.ServiceResultModel;
import com.ljf.common.utils.ServiceResultUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * 菜单列表定义  服务接口实现
 *
 * @author LJF
 * @since 2024-10-17
 */
@Service
public class AuthorityBaseMenuTabulationServiceImpl extends BasisServiceImpl<AuthorityBaseMenuTabulationDomainService, AuthorityBaseMenuTabulationValidator, AuthorityBaseMenuTabulationRepository, AuthorityBaseMenuTabulationQuery, AuthorityBaseMenuTabulationVO, AuthorityBaseMenuTabulation, AuthorityBaseMenuTabulationCommand> implements IAuthorityBaseMenuTabulationService {

    /**
     * 权限树
     *
     * @return
     * @throws ServiceException
     */
    @Override
    public ServiceResultModel<AuthorityBaseMenuTabulationMainMenuVO> tree() throws ServiceException {
        List<AuthorityBaseMenuTabulationMainMenuVO> resultList = domainService.tree();
        return ServiceResultUtil.success(resultList);
    }

    /**
     * 权限按钮
     *
     * @param componentUrl
     * @return
     * @throws ServiceException
     */
    @Override
    public ServiceResultModel<AuthorityBaseMenuTabulationButtonMethodVO> button(String componentUrl) throws ServiceException {
        validator.checkButton(componentUrl);
        AuthorityBaseMenuTabulationButtonMethodVO result = domainService.button(componentUrl);
        List<AuthorityBaseMenuTabulationButtonMethodVO> resultList = new ArrayList<>();
        resultList.add(result);
        return ServiceResultUtil.success(resultList);
    }

    /**
     * 菜单树
     *
     * @return
     * @throws ServiceException
     */
    @Override
    public ServiceResultModel<AuthorityBaseMenuTabulationMainMenuVO> queryMenuTree() throws ServiceException {
        List<AuthorityBaseMenuTabulationMainMenuVO> resultList = domainService.queryMenuTree();
        return ServiceResultUtil.success(resultList);
    }

    /**
     * 根据ID查询菜单树排序
     *
     * @param id
     * @return
     * @throws ServiceException
     */
    @Override
    public ServiceResultModel<AuthorityBaseMenuTabulationVO> querySortById(Long id) throws ServiceException {
        validator.checkQuerySortById(id);
        List<AuthorityBaseMenuTabulationVO> resultList = domainService.querySortById(id);
        return ServiceResultUtil.success(resultList);
    }

    /**
     * 修改菜单列表排序
     *
     * @param command
     * @return
     * @throws ServiceException
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ServiceResultModel editSort(AuthorityBaseMenuTabulationSortCommand command) throws ServiceException {
        validator.checkEditSort(command);
        domainService.editSort(command);
        return ServiceResultUtil.success();
    }

    /**
     * 根据ID查询菜单树明细
     *
     * @param id
     * @return
     * @throws ServiceException
     */
    @Override
    public ServiceResultModel<AuthorityBaseMenuTabulationDetailVO> queryDetailById(Long id) throws ServiceException {
        validator.checkQueryDetailById(id);
        AuthorityBaseMenuTabulationDetailVO result = domainService.queryDetailById(id);
        List<AuthorityBaseMenuTabulationDetailVO> resultList = new ArrayList<>();
        resultList.add(result);
        return ServiceResultUtil.success(resultList);
    }

    /**
     * 修改菜单列表明细
     *
     * @param command
     * @return
     * @throws ServiceException
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ServiceResultModel editDetail(AuthorityBaseMenuTabulationDetailCommand command) throws ServiceException {
        validator.checkEditDetail(command);
        domainService.editDetail(command);
        return ServiceResultUtil.success();
    }

    /**
     * 根据ID查询菜单关联后端
     *
     * @param id
     * @return
     * @throws ServiceException
     */
    @Override
    public ServiceResultModel<AuthorityBaseMenuTabulationBackendVO> queryBackendById(Long id) throws ServiceException {
        validator.checkQueryBackendById(id);
        AuthorityBaseMenuTabulationBackendVO result = domainService.queryBackendById(id);
        List<AuthorityBaseMenuTabulationBackendVO> resultList = new ArrayList<>();
        resultList.add(result);
        return ServiceResultUtil.success(resultList);
    }

    /**
     * 修改菜单列表关联后端
     *
     * @param command
     * @return
     * @throws ServiceException
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ServiceResultModel editBackend(AuthorityBaseMenuTabulationBackendCommand command) throws ServiceException {
        validator.checkEditBackend(command);
        domainService.editBackend(command);
        return ServiceResultUtil.success();
    }

    /**
     * 根据ID查询菜单按钮方法
     *
     * @param id
     * @return
     * @throws ServiceException
     */
    @Override
    public ServiceResultModel<AuthorityBaseMenuTabulationMethodVO> queryMethodById(Long id) throws ServiceException {
        validator.checkQueryMethodById(id);
        AuthorityBaseMenuTabulationMethodVO result = domainService.queryMethodById(id);
        List<AuthorityBaseMenuTabulationMethodVO> resultList = new ArrayList<>();
        resultList.add(result);
        return ServiceResultUtil.success(resultList);
    }

    /**
     * 修改菜单列表按钮方法
     *
     * @param command
     * @return
     * @throws ServiceException
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ServiceResultModel editMethod(AuthorityBaseMenuTabulationMethodCommand command) throws ServiceException {
        validator.checkEditMethod(command);
        domainService.editMethod(command);
        return ServiceResultUtil.success();
    }

    /**
     * 修改菜单列表激活状态
     *
     * @param command
     * @return
     * @throws ServiceException
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ServiceResultModel editActivation(AuthorityBaseMenuTabulationActivationCommand command) throws ServiceException {
        validator.checkEditActivation(command);
        domainService.editActivation(command);
        return ServiceResultUtil.success();
    }

    /**
     * 修改菜单列表关联权限组
     *
     * @param command
     * @return
     * @throws ServiceException
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ServiceResultModel editPermissionGroup(AuthorityBaseMenuTabulationPermissionGroupCommand command) throws ServiceException {
        validator.checkEditPermissionGroup(command);
        domainService.editPermissionGroup(command);
        return ServiceResultUtil.success();
    }

    /**
     * 根据ID查询菜单权限组
     *
     * @param id
     * @return
     * @throws ServiceException
     */
    @Override
    public ServiceResultModel<AuthorityBaseMenuTabulationPermissionGroupVO> queryPermissionGroupById(Long id) throws ServiceException {
        validator.checkQueryPermissionGroupById(id);
        AuthorityBaseMenuTabulationPermissionGroupVO result = domainService.queryPermissionGroupById(id);
        List<AuthorityBaseMenuTabulationPermissionGroupVO> resultList = new ArrayList<>();
        resultList.add(result);
        return ServiceResultUtil.success(resultList);
    }

}
